/*
 * @Author: wangtao
 * @Date: 2021-01-14 16:00:34
 * @LastEditors: 汪滔
 * @LastEditTime: 2021-02-01 16:40:40
 * @Description: file content
 */
import React, {Component, Fragment} from 'react';
import {
  TouchableOpacity,
  StyleSheet,
  View,
  Text,
  Image,
 
} from 'react-native';
import {
  px2dp,
  mainBgColorWhite,
  fontColorBlack,
} from '../../../../../common/styles/index';
import { msg,  _, cache} from '../../../../../common';

import {
  iconDelete,
} from '../../../../../image';
import AddressItem from './address-item';
import AsyncStorage from '@react-native-community/async-storage';

export default class AddressHistory extends Component {
  componentDidMount() {}

  componentWillUnmount() {}

  render() {
    const {addressSearchHistoryList, selectMapPosition} = this.props;
    return (
      <View style={styles.historyWrap}>
        <View style={styles.header}>
          <Text style={styles.headerTitle}>历史记录</Text>
          <TouchableOpacity activeOpacity={0.8} onPress={()=>{
            this.clearHistory()
          }}>
            <Image
              source={iconDelete}
              resizeMode="stretch"
              style={styles.deleteImg}
            />
          </TouchableOpacity>
        </View>
        {addressSearchHistoryList.map((item) => {
          return (
            <AddressItem
              addressInfo={item}
              selectItem={selectMapPosition}
              type="history"
            />
          );
        })}
      </View>
    );
  }

  clearHistory=()=>{
    const {onChange} = this.props
    msg.emit('app:messageBox', {
      isVisible:true,
      title:'是否清除历史搜索记录',
      text:'清除历史搜索记录后不可恢复',
      okText:'确定',
      cancelText:'取消',
      okFn:()=>{
        AsyncStorage.setItem(
          cache.ADDRESS_SEARCH_LIST_RELEASE_SOURCE,
          JSON.stringify([]),
        );
        onChange('addressSearchHistoryList',[])
      },
      cancelFn:()=>{
          console.log('🚀🚀🚀wimi======>>>cancelFn',)
      },
   })
  }
}
const styles = StyleSheet.create({
  historyWrap: {
    flex: 1,
    backgroundColor: mainBgColorWhite,
    marginTop: px2dp(20),
  },
  header: {
    flexDirection: 'row',
    justifyContent: 'space-between',
    alignItems: 'center',
    height: px2dp(104),
    paddingHorizontal: px2dp(32),
  },
  deleteImg: {
    width: px2dp(28),
    height: px2dp(28),
  },
  headerTitle: {
    fontSize: px2dp(32),
    color: fontColorBlack,
    fontWeight: 'bold',
  },
});
